package com.wen;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;

@SpringBootTest
public class SendMail {
    @Autowired
    JavaMailSenderImpl mailSender;
    @Test
    public void test1(){
        //简单的邮件发送
        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject("致温帅的一封信");
        message.setText("将来你一定会感谢这么帅气还这么努力的你");
        message.setTo("1433787828@qq.com");
        message.setFrom("1433787828@qq.com");
        mailSender.send(message);
    }
    @Test
    public void test2() throws MessagingException {
        //复杂的邮件发送
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true);
        helper.setSubject("挑战连续一百天不帅气");
        helper.setText("<h1>第一天：挑战失败！</h1>",true);
        helper.addAttachment("2020java后端学习路线.jpg", new File("C:\\Users\\Lenovo\\Desktop\\2020java后端学习路线.jpg"));
        helper.setTo("1433787828@qq.com");
        helper.setFrom("1433787828@qq.com");
        mailSender.send(mimeMessage);

    }
}
